<!DOCTYPE >
<html lang="zh-cn">
<head>
		<title>后台管理-礼物</title>
    <% include ../partials/head %>
    <script type="text/javascript">
    var oGift ={
        operator:function(){
            $(".box-content").on("click",".public",function(){
                $this = $(this)
                if(window.confirm('你确定上架？')){
                    $.post("/admin/gift/publish",{
                        "objectId":$this.attr('giftId'),
                    },function(json){
                        if(json.code==0){
                            history.go(0);
                        }else{
                            alert(json.msg);
                        }
                    },'json');
                }else{
                    //取消
                }
            }).on("click",".cancel",function(){
                $this = $(this)
                if(window.confirm('你确定下架该礼物么？')){
                    $.post("/admin/gift/disable",{
                        "objectId":$this.attr('topicId'),
                    },function(json){
                        if(json.code==0){
                            history.go(0);
                        }else{
                            alert(json.msg);
                        }
                    },'json');
                }else{
                    //取消
                }
            })
        },
        change:function(){
            // var state =window.location.href.split("=")[1];
            // $("#topic-filter option[value='"+state+"']").attr("selected","selected");
            // $("#topic-filter").on("change",function(){
            //     var value = $(this).children('option:selected').val(); 
            //     window.location.href="/admin/topic?status="+value;
            // })
        },
        init:function(){
            this.operator();
            this.change();
        }
    }
    $(document).ready(function(){
        oGift.init();
    })
    </script>
</head>
<body>
	<header>
    <% include ../partials/header %>
  </header>
  <div class="ch-container">
    <div class="row">
      <% include ../partials/sidebar %>
      <!-- 页面内容 -->
      <div id="content" class="col-lg-10 col-sm-10">
        <div class="row">
          <div class="box col-md-12">
            <div class="box-inner">
              <div class="box-header well" data-original-title="">
                <div class="control-group">
                  <div class="controls">
                    <label class="control-label" for="selectError">筛选:&nbsp&nbsp&nbsp </label>
                    <a class="btn btn-default pull-right" href="/admin/gift/add" >
                     <i class="glyphicon glyphicon-plus green"></i> 添加礼物
                   </a>
                  </div>
                  
                </div>
              </div>

              <div class="box-content">
                <table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
                  <thead>
                    <tr>
                      <th>名字</th>
                      <th>介绍</th>
                      <th>图片</th>
                      <th>价格</th>
                      <th>优先级</th>
                      <th>是否上架</th>
                      <th>操作</th>
                    </tr>
                  </thead>

                  <tbody>
                    <% if (typeof gifts != "undefined") { %>
                      <% gifts.forEach(function(gift) { %>
                        <tr>
                          <td class="center"><%= gift.get("name") %></td>
                          <td class="center"><%= gift.get("info") %></td>
                          <td class="center"><a  href="<%=gift.get('img').url()%>" target="_blank"> <img style="max-height:100px" src="<%=gift.get('img').url()%>"></a></td>
                          <td class="center"><%= gift.get("price") %>时光</td>
                          <td class="center"><%= gift.get("priority") %></td>
                          <td class="center">
                            <% if(gift.get('status')==0){%>
                            未上架
                            <%}else{%>
                            已上架
                            <%}%>
                          </td>
                          <td class="center">
                            <% if(gift.get("status")==1){ %>
                                <a class="btn btn-info" href="/admin/gift/edit?objectId=<%=gift.id %>">
                                      <i class="glyphicon glyphicon-zoom-in icon-white"></i>
                                     编辑 
                                  </a> 
                                <span class="btn btn-danger cancel" giftId=<%=gift.id%>>
                                  <i class="glyphicon glyphicon-minus-sign icon-white"></i>
                                 下架 
                                </span>   
                            <% } %>
                            <% if(gift.get("status")==0){ %>
                                  <a class="btn btn-info" href="/admin/gift/edit?objectId=<%=gift.id %>">
                                      <i class="glyphicon glyphicon-zoom-in icon-white"></i>
                                     编辑 
                                  </a> 
                                  <span class="btn btn-success public" giftId=<%=gift.id%>>
                                      <i class="glyphicon glyphicon-ok icon-white"></i>
                                     上架
                                    </span> 
                            <% } %>

                          </td>
                        </tr>
                      <% }) %>
                    <% } %>
                  </tbody>
                </table>
              </div>

            </div>
          </div>
        </div>
      </div>

    </div>
    <% include ../partials/footer %>
  </div>
  <% include ../partials/external %>
</body>
</html>
